
//
// 110609 - AH - Created.
// 110614 - AH - Finished implementation, renamed to proper name and added
//               missing java doc.
//

package org.soekrat.gui.swing.forest;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.TreeCellEditor;

import org.soekrat.engine.SoekratName;
import org.soekrat.engine.forest.Tree;

/**
 * <p>
 *   {@link TreeCellEditor} for 
 *   {@link JTree} that shows
 *   {@link Tree} hierarchy.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class SoekratTreeCellEditor extends DefaultTreeCellEditor
{
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param tree View.
   */
  public SoekratTreeCellEditor(JTree tree)
  {
    super(tree, SoekratTreeCellRenderer.INSTANCE);
  }
  
  // Specified in TreeCellEditor.
  public Component getTreeCellEditorComponent(JTree tree, Object val,
    boolean isSelected, boolean expanded, boolean leaf, int row)
  {
    String text=val.toString();
    if (val instanceof Tree)
    {
      SoekratName sname=((Tree)val).getSoekratName();
      text=sname.toString();
    }
    
    return super.getTreeCellEditorComponent(tree, text, isSelected, expanded, 
      leaf, row);
  }
  
}
